<template>
	<view class="sure_container">
		<view class="sure_top" v-if="address!=null" @click="toaddress">
			<image src="../../static/index/address.png" mode=""></image>
			<view class="sure_address">
				<view>
					<text class="sure_name">{{address.name}}</text><text class="sure_phone">{{address.phone}}</text>
				</view>
				<view class="sure_dizhi">
					{{address.province}}{{address.city}}{{address.area}}{{address.detail}}
				</view>
			</view>
			<u-icon name="arrow-right" class="sure_right" color="#B5B5B5" size="38"></u-icon>
		</view>
		<view class="sure_tops" v-if="address==null" @click="toaddress">
			选择收货地址
		</view>
		<view class="sure_center" v-if="goods!=null">
			<view class="sure_shop">
				<image :src="img" mode=""></image>
				<view class="sure_induc">
					<view class="sure_more">
						{{goods.goods_name}}
					</view>
					<view class="sure_jifen">
						{{goods.goods_price}}积分
					</view>
				</view>
			</view>
			<view class="sure_buy">
				<view class="sure_num">
					购买数量
				</view>
				<u-number-box v-model="value" @change="valChange" :min="1"></u-number-box>
			</view>
			<view class="sure_two">
				<view class="sure_num">
					配送方式<text style="color: #cecece;margin-left: 32rpx;">普通配送</text>
				</view>
				<view class="">
					<text style="color: #cecece;">快递免邮</text><text
						style="font-family: '楷体';margin-left: 20rpx;color: #cecece;"></text>
				</view>
			</view>
			<view class="sure_three">
				<u-form-item label="订单备注" label-width="142rpx" :border-bottom="false">
					<u-input class="uni-input" placeholder="选填,请先和商家协商一致" v-model="text" />
				</u-form-item>
			</view>
			<!-- <view class="sure_fore">
				<text style="font-size: 24rpx;color: #cecece;font-weight: 300;"></text><text style="margin-left: 14rpx;">小计：</text><text style="font-size:32rpx ;color: #333333;">3399积分</text>
			</view> -->
		</view>
		<view class="sure_footer">
			<view class="sure_left">
				<text style="font-size: 32rpx;color: #333333;padding-left: 30rpx;"> 合计：{{price}}</text><text
					style="font-size: 32rpx;color: #333333;">积分</text>
			</view>
			<view class="sure_right" @click="xiadan">
				提交订单
			</view>
		</view>
	</view>
</template>

<script>
	import {
		addorder,
		xiadan
	} from "../../api/product.js"
	export default {
		data() {
			return {
				value: 1,
				goodsid: null,
				skuid: null,
				address: null,
				goods: null,
				price: null,
				img: "",
				text: "",
				isms:0
			}
		},
		watch: {
			value: {
				handler(val, oldVal) {
					this.price = val * this.goods.goods_price
				},
				deep: true
			}
		},
		onLoad(e) {
			this.goodsid = e.goodsid
			this.skuid = e.skuid
			if(e.isms){
				this.isms=1
			}
			this.getinfo()
			
		},
		onShow() {
			uni.$once('setAddress', (data) => {
				this.address = data
				uni.$off('setAddress')
			})
		},
		methods: {
			toaddress() {
				uni.navigateTo({
					url: "/pages/address/address?type=true"
				})
			},
			valChange(e) {
				console.log('当前值为: ' + e.value)
				console.log(this.value)
			},
			async getinfo() {
				let res = await this.post(addorder, {
					user_id: uni.getStorageSync("userInfo").id,
					goods_id: this.goodsid,
					sku_id: this.skuid,
					seckill:this.isms
				})
				this.address = res.data.address
				this.goods = res.data.product
				this.price = res.data.product.goods_price
				this.img = res.data.product.image.file_path
			},
			async xiadan() {
				let res = await this.post(xiadan, {
					user_id: uni.getStorageSync("userInfo").id,
					goods_id: this.goodsid,
					sku_id: this.skuid,
					pay_type: 3,
					num: this.value,
					buyer_remark: this.text,
					address_id:this.address.id,
					seckill:this.isms
				})
				uni.navigateTo({
					url:"/pages/order/moneyDesk?id="+res.data.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-input {
		width: 500rpx !important;
	}

	page {
		background-color: #F1F1F1;
	}

	.sure_tops {
		position: relative;
		width: 690rpx;
		height: 140rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 40rpx;
	}

	.sure_container {
		padding: 30rpx;

		.sure_top {
			position: relative;
			width: 690rpx;
			height: 182rpx;
			background: #FFFFFF;
			border-radius: 12rpx;

			image {
				position: absolute;
				top: 50%;
				left: 50rpx;
				transform: translate(-50%, -50%);
				width: 38rpx;
				height: 42rpx;

			}

			.sure_address {
				position: absolute;
				top: 50%;
				left: 330rpx;
				transform: translate(-50%, -50%);
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				width: 456rpx;
				height: 119rpx;

				.sure_name {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #000000;
					opacity: 1;
				}

				.sure_phone {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					opacity: 1;
					margin-left: 30rpx;
				}

				.sure_dizhi {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #000000;
					opacity: 1;
				}
			}

			.sure_right {
				position: absolute;
				top: 50%;
				right: 10rpx;
				transform: translate(-50%, -50%);
			}
		}

		.sure_center {
			width: 690rpx;
			height: 550rpx;
			background-color: #FFFFFF;
			opacity: 1;
			border-radius: 12rpx;
			margin-top: 45rpx;
			padding: 0 20rpx;

			.sure_shop {
				width: 650rpx;
				height: 166rpx;
				display: flex;
				justify-content: space-between;
				padding-top: 30rpx;
				box-sizing: border-box;

				image {
					width: 166rpx;
					height: 166rpx;
				}

				.sure_induc {
					width: 442rpx;
					height: 166rpx;

					.sure_more {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #000000;
						opacity: 1;
					}

					.sure_jifen {
						font-size: 41rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #000000;
						opacity: 1;
						margin-top: 43rpx;
					}
				}
			}

			.sure_buy {
				display: flex;
				justify-content: space-between;
				margin-top: 80rpx;

				.sure_num {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #333333;
					opacity: 1;

				}
			}

			.sure_two {
				display: flex;
				justify-content: space-between;
				margin-top: 26rpx;
			}

			.sure_three {
				display: flex;
				justify-content: space-between;
				margin-top: 8rpx;
			}

			.sure_fore {
				text-align: right;
				margin-bottom: 30rpx;
				box-sizing: border-box;
			}
		}

		.sure_footer {
			position: fixed;
			bottom: 45rpx;
			width: 690rpx;
			height: 88rpx;
			display: flex;

			.sure_left {
				width: 466rpx;
				height: 88rpx;
				line-height: 88rpx;
				background-color: #FFFFFF;
				border-radius: 12rpx 0px 0px 12rpx;
			}

			.sure_right {
				width: 224rpx;
				height: 88rpx;
				background: #008573;
				opacity: 1;
				border-radius: 0px 12rpx 12rpx 0px;
				text-align: center;
				line-height: 88rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}
</style>
